#include "ToyMgr.h"


CToyMgr::CToyMgr(CTaScene*  pscene)
{
    //init
    m_root = pscene->GetRootModel();

    GetBoneFromObject(m_root);
}


CToyMgr::~CToyMgr()
{
    m_bones.clear();
}


CTaObject*  CToyMgr::GetRoot()
{
    return  m_root;
}


CTaObject*  CToyMgr::GetBoneByName(const char* bname)
{
    map<string,CTaObject*>::iterator it = m_bones.find(string(bname));


    if(it==m_bones.end())
        return   NULL;
    else
        return  it->second;
}

void    CToyMgr::GetBoneFromObject(CTaObject* pTobj)
{
    CTaObject *child;
    int childcount;
    LPCTSTR   bname;

    if(pTobj->GetType()==TA_OBJECT_JOINT)
    {
        bname = pTobj->GetName();
        m_bones.insert( pair<string,CTaObject*>(string(bname),pTobj) );
    }

    childcount = pTobj->GetChildCount();

    for(int i=0;i<childcount;i++)
    {
        child = pTobj->GetChild(i);
        GetBoneFromObject(child);
    }


}
